import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'shareOptionManageM',

  state: {},
  effects: {
    //获取期权管理表格信息
    *queryOptionList({ payload, callback }, { call, put }) {
      const response = yield call(api.shareOptionManage.queryOptionList, payload);
      if (response?.code == 0) {
        response.data.columns &&
          response.data.columns.map((item) => {
            if (item.key == 'notional' || item.key == 'strike') {
              item.type = 'money';
            }
          });
        callback('success', response.data);
      } else {
        callback('fail');
        message.error(response?.msg || '获取期权管理表格信息失败');
      }
    },

    //根据BundleId删除信息
    *deleteOptionByBookId({ payload, callback }, { call, put }) {
      const response = yield call(api.shareOptionManage.deleteOptionByBookId, payload);
      if (response?.code == 0) {
        callback('success');
      } else {
        callback('fail');
        message.error(response.msg || '删除信息失败');
      }
    },
    //期权市值模板上传
    *uploadFile({ payload, callback }, { call, put }) {
      const response = yield call(api.shareOptionManage.uploadFile, payload);
      callback(response);
    },
    //执行授信跑批
    *runCreditMonitor({ payload, callback }, { call, put }) {
      const response = yield call(api.shareOptionManage.runCreditMonitor, payload);
      callback(response);
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
